package sample;

import java.io.File;

public class CompressTest {
  public static   String url= "";
    public static void compress(String sourceUrl)throws Exception{

        File sourceFile = new File(sourceUrl);
        System.out.println(sourceFile.isDirectory());
        if(sourceFile.isDirectory()){//判断传的是文件

             url = "F:\\temp\\"+sourceFile.getName()+"\\";//指定的文件路径

            File fi = new File(url);
            fi.mkdirs();//创建文件夹

            File [] files = sourceFile.listFiles();
            for(File f:files){

                if(f.isDirectory()){//是文件夹
                    String name = f.getName();
                    int x= name.indexOf(".");//判断文件夹名称是否带.
                    if(x!=-1){//文件夹带.
                        new CompactAlgorithm(new File( url,f.getName()+".itz")).zipFiles(f);
                        new File(url+f.getName()+".itz").renameTo(new File(url+f.getName()));
                        DeleteFileUtil.deleteFile(url+f.getName()+".itz");
                    }else{//文件夹不带.
                        if("vivo".equals(f.getName())) {
                            new CompactAlgorithm(new File(url, f.getName() + ".itz")).zipFiles(f);
                            new File(url + f.getName() + ".itz").renameTo(new File(url + f.getName()));
                            DeleteFileUtil.deleteFile(url + f.getName() + ".itz");
                            DeleteFileUtil.deleteDirectory(url + f.getName());
                        }else  if("lockscreen".equals(f.getName())) {
                            System.out.println("===============" + f.getName());
                            new CompactAlgorithm(new File(url, f.getName() + ".itz")).zipFiles(f);
                            new File(url + f.getName() + ".itz").renameTo(new File(url + f.getName()));
                            DeleteFileUtil.deleteFile(url + f.getName() + ".itz");
                            DeleteFileUtil.deleteDirectory(url + f.getName());//
                        }else if("framework-res".equals(f.getName())){
                            new CompactAlgorithm(new File(url, f.getName() + ".itz")).zipFiles(f);
                            new File(url + f.getName() + ".itz").renameTo(new File(url + f.getName()));
                            DeleteFileUtil.deleteFile(url + f.getName() + ".itz");
                            DeleteFileUtil.deleteDirectory(url + f.getName());//
                        }else{
                            Ioliu.copy(f.toString(),url+"/"+f.getName());
                        }
                    }
                }else{//不是文件夹
                    Ioliu.fileCopy(f.toString(),url+f.getName());
                }
            }
        }else{//传入的是文件
            //File f = new File("F:\\测试");
            new CompactAlgorithm(new File( "F:",sourceFile.getName()+".itz")).zipFiles(sourceFile);
        }

    }

    public static  void compress2(String parth){
        File f = new File(parth);
        new CompactAlgorithm(new File( "F:\\temp",f.getName()+".itz")).zipFiles(f);
        DeleteFileUtil.deleteDirectory(parth);
    }



//    public  static void  main(String [] args)throws Exception{
//
//        compress("E:\\第二阶段素材\\白富美密码锁");
//        compress2(url);
//
//    }



}
